<script>
re = /cat/g;
console.log(re.test("catxxxxcatyyyy")); // true

re = new RegExp("cat", "g");
console.log(re.test("catxxxxcatyyyy")); // true

var pattern1 = /\[bc\]at/i;
console.log(pattern1.global); //false
console.log(pattern1.ignoreCase); //true
console.log(pattern1.multiline); //false
console.log(pattern1.lastIndex); //0
console.log(pattern1.source); //”\[bc\]at”

var text = "mom and dad and baby";
var pattern = /mom( and dad( and baby)?)?/gi;
var matches = pattern.exec(text);
console.log(matches.index); //0
console.log(matches.input); //”mom and dad and baby”
console.log(matches[0]); //”mom and dad and baby”
console.log(matches[1]); //” and dad and baby”
console.log(matches[2]); //” and baby”
</script>